<?php

namespace App\Lib;

use AlibabaCloud\SDK\Dyplsapi\V20170525\Dyplsapi;
use AlibabaCloud\SDK\Dyplsapi\V20170525\Models\AddAxnTrackNoRequest;
use AlibabaCloud\SDK\Dyplsapi\V20170525\Models\BindAxbRequest;
use AlibabaCloud\SDK\Dyplsapi\V20170525\Models\UnbindSubscriptionRequest;
use AlibabaCloud\SDK\Dyplsapi\V20170525\Models\UpdateSubscriptionRequest;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Illuminate\Support\Facades\Log;

class DyplsapiClient
{
    private static $phoneX = '17177789578';
    private static $poolKey = 'FC100000175174106';
    public static function createClient(){
        $config = new Config([
            // 您的AccessKey ID
            "accessKeyId" => env('DYPLS_ACCESS_KEY_ID'),
            // 您的AccessKey Secret
            "accessKeySecret" => env('DYPLS_SECRET_ID')
        ]);
        $config->endpoint = env('DYPLS_END_POINT');

        return new Dyplsapi($config);
    }
    // 解绑
    public static function unbind($client, $params){
        $req = new UnbindSubscriptionRequest($params);
        $resp = $client->unbindSubscription($req);
        if (!Utils::equalString($resp->body->code, "OK")) {
            throw new TeaError([
                "code" => $resp->body->code,
                "message" => $resp->body->message
            ]);
        }
        return $resp;
    }
    // 更新关联关系
    public static function updateBind($client, $params){
        $req = new UpdateSubscriptionRequest($params);
        $resp = $client->updateSubscription($req);
        if (!Utils::equalString($resp->body->code, "OK")) {
            throw new TeaError([
                "code" => $resp->body->code,
                "message" => $resp->body->message
            ]);
        }
        return $resp;
    }
    // 绑定
    public static function bindAxb($client, $params){
        $req = new BindAxbRequest($params);
        $resp = $client->bindAxb($req);
        if (!Utils::equalString($resp->body->code, "OK")) {
            throw new TeaError([
                "code" => $resp->body->code,
                "message" => $resp->body->message
            ]);
        }
        return $resp;
    }



}
